<!-- 合作申请记录 -->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="90px">
      <el-form-item label="关键词" prop="searchValue">
        <el-input
          v-model="queryParams.searchValue"
          placeholder="请输入合作发起方"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="合作发起方" align="center" prop="channelName" />
      <el-table-column label="发起人" align="center" prop="sponsor" />
      <el-table-column label="发起人电话" align="center" prop="sponsorPhone" />
      <el-table-column label="合作接收方" align="center" prop="companyName" />
      <el-table-column label="合作申请状态" align="center" prop="verifyStatus">
        <template slot-scope="{ row }">
          <!-- 审核状态: 0待审核 1已通过 2已驳回 3已取消 -->
          <el-tag v-if="row.verifyStatus === 3">已取消</el-tag>
          <el-tag v-else-if="row.verifyStatus === 2" type="danger"
            >已驳回</el-tag
          >
          <el-tag v-else-if="row.verifyStatus === 1" type="success"
            >已通过</el-tag
          >
          <el-tag v-else type="warning">审核中</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="审核人" align="center" prop="verifier" />
      <el-table-column label="审核人电话" align="center" prop="verifierPhone" />
      <el-table-column label="审核说明" align="center" prop="verifyExplain" />
      <el-table-column label="审核时间" align="center" prop="verifyTime" />
      <el-table-column label="发起时间" align="center" prop="createTime" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="120px"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
          v-if="verifier && scope.row.verifyStatus === 0"
          size="mini"
          type="text"
          @click="handleAudit(scope.row)"
          >审核</el-button
          >
          <el-button
          v-if="!verifier && scope.row.verifyStatus === 0"
          size="mini"
          type="text"
          @click="handleDelete(scope.row)"
          >取消合作申请</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getApplyList, updateApplyCooperate } from "@/api/facilitator";

export default {
  name: "CooperationRecord",
  props: {
    // 是否是审核权限, 否则则是申请权限
    verifier: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        searchValue: ""
      },
      // 总条数
      total: 0,
      dataList: [],
    };
  },
  created() {
    this.getList();
  },
  activated() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      getApplyList(this.queryParams)
        .then((response) => {
          this.dataList = response.rows;
          this.total = response.total;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      Object.assign(this.$data.queryParams, this.$options.data().queryParams);
      this.getList();
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal
        .confirm("是否确认取消合作申请？")
        .then(function () {
          return updateApplyCooperate({ id: row.id, verifyStatus: 3 });
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("取消成功");
        })
        .catch(() => {});
    },
    handleAudit(row) {
      this.$emit('openAudit', row)
    }
  },
};
</script>

<style lang="scss" scoped></style>
